package com.jianyun.jyzs.adapter;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.jianyun.jyzs.R;
import com.jianyun.jyzs.bean.OaAppBean;
import com.jianyun.jyzs.utils.LoginCache;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by yangshijun on 2018/9/5.
 */

public class OaMyGridAdapter extends BaseAdapter {


    private Context mContext;
    private List<OaAppBean.ItemBean> mListItems;
    private int workNums;

    public OaMyGridAdapter(Context context, List<OaAppBean.ItemBean> listItems) {
        mContext = context;
        mListItems = listItems;
    }

    public void setmListItems(List<OaAppBean.ItemBean> listItems) {
        this.mListItems = listItems;
        notifyDataSetChanged();
    }

    public void setWorkNum(int wrokNum) {
        this.workNums = wrokNum;
        Log.i("test","待办个数："+workNums);
        //notifyDataSetChanged();
    }


    @Override
    public int getCount() {
        return mListItems == null ? 0 : mListItems.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHodler viewHodler;
        if (convertView == null) {
            viewHodler = new ViewHodler();
            convertView = View.inflate(mContext, R.layout.item_oa_recyclerview, null);
            viewHodler.image = convertView.findViewById(R.id.image);
            viewHodler.text = convertView.findViewById(R.id.text_icon);
            viewHodler.tvUnread = convertView.findViewById(R.id.tv_unRead);
            convertView.setTag(viewHodler);
        } else {
            viewHodler = (ViewHodler) convertView.getTag();
        }
        viewHodler.text.setText(mListItems.get(position).getAppName());
       String path= LoginCache.getInstance().getLoginCache().getErpRootUrl() + mListItems.get(position).getAppImg();
        //Log.d("img",path);
        //Picasso.with(mContext).load(path).into(viewHodler.image);
        Glide.with(mContext).load(path).into(viewHodler.image);
        //Picasso.with(mContext).load(LoginCache.getInstance().getLoginCache().getErpRootUrl() + mListItems.get(position).getAppImg()).into(viewHodler.image);
        if ("workflow_count".equals(mListItems.get(position).getPush_count_name()) && workNums != 0) {
            viewHodler.tvUnread.setVisibility(View.VISIBLE);
            viewHodler.tvUnread.setText(workNums + "");

        } else {
            viewHodler.tvUnread.setVisibility(View.INVISIBLE);
        }


        return convertView;
    }

    class ViewHodler {
        ImageView image;
        TextView text;
        TextView tvUnread;
    }
}
